<?php

/**
 *      [CodeJm!] Author CodeJm[codejm@163.com].
 *
 *      后台主页
 *      $Id: Index.php 2014-07-27 18:51:50 codejm $
 */

class IndexController extends \Core_BackendCtl {

    /**
     * 后台主页
     *
     */
    public function indexAction() {
        $order = new OrderModel();
        $list =  $order->OrderCount();
        $weekcase = $order->weekOrder();
        $finsh = $order->weekfinshOrder();
        
        $paid_count  = 0;
        $not_paid_count  = 0;
        $already_car_count  = 0;
        $not_confirm_count  = 0;
            
        $total_fee = 0;
        $paid_fee = 0;
        $not_paid_fee = 0;
        $coupon = 0;
        
        if(!empty($list)){
            foreach($list as $v){
                if($v['order_state'] == 1 && $v['order_place'] == 1 ){
                    $paid_count++;
                }
                if($v['order_state'] == 0 && $v['order_place'] == 1 ){
                    $not_paid_count++;
                }
                if($v['order_state'] == 0 && $v['order_place'] == 2 ){
                    $not_confirm_count++;
                }
                if($v['order_state'] == 2){
                    $already_car_count++;
                }
            }
        }
        
        if(!empty($weekcase)){
           foreach($weekcase as $v){
               $total_fee += $v['must_price'];
               $paid_fee += $v['already_price'] + $v['final_payment'];
               $coupon += $v['card_fee'];
           }
           
        }
        
        $datelist = array();
        $datestr = '';
        $order_finsh = 0;
        if(!empty($finsh)){
            foreach($finsh as $v){               
               if(!empty($v['final_payment_time']) && $v['order_state'] == 3){
                   $key = date('m/d',$v['final_payment_time']);
                   $datelist[$key] +=1; 
                   $order_finsh +=1;
               }
           }
            
            for($i=6;$i>=0;$i--){
               $key =  date('m/d',(time()-$i*24*3600));
               if(isset($datelist[$key])){
                   $datestr .= '["'.$key.'",'.$datelist[$key].'],';
               }else{
                    $datestr .= '["'.$key.'",0],';
               }
           }
 
        }else{
            for($i=6;$i>=0;$i--){
               $key =  date('m/d',(time()-$i*24*3600));
               $datestr .= '["'.$key.'",0],';
           }
        }
        
        $datestr = trim($datestr,',');
        $not_paid_fee = $total_fee - $paid_fee - $coupon;
        $not_paid_fee =  ($not_paid_fee >0)?$not_paid_fee:0;
        
        //echo $paid_count,$not_paid_count,$not_confirm_count;exit;
        $this->_view->assign('order_finsh', $order_finsh);
        $this->_view->assign('paid_count', $paid_count);
        $this->_view->assign('not_paid_count', $not_paid_count);
        $this->_view->assign('not_confirm_count', $not_confirm_count);
        $this->_view->assign('already_car_count', $already_car_count);
        $this->_view->assign('datestr', $datestr);
        $this->_view->assign('paid_fee', $paid_fee);
        $this->_view->assign('total_fee', $total_fee);
        $this->_view->assign('coupon', $coupon);
        $this->_view->assign('not_paid_fee', $not_paid_fee);
        $this->_view->assign('pageTitle', '后台主页');
    }

}

?>
